<template>
<view class="container">
	<view class="view_line"></view>
	<view class="position">
		<view class="header">
			<view class="search" >
				<icon size="14" type="search"></icon>
				<input @input="search" placeholder="请输入机构名称" value=""/>
			</view>
		</view>
		<!-- 搜索选择-->
		<view class="list_sort">
			<view class="sort_list">
				<view class="picker" @click="citySelect">
					<text>{{city}}</text>
					<image src="/static/img/buttom.png"></image>
				</view>
			</view>
			
			<view class="sort_list">
				<picker @change="bindJobChange" :value="jobIndex" :range="job" 
				range-key="name" data-index="jobIndex">
					<view class="picker">
					{{jobText}}
					<image src="/static/img/buttom.png">
					</view>
				</picker>
			</view>
			
			<view class="sort_list">
				<picker @change="bindMoneyChange" :value="moneyIndex" :range="moneyArr"
				data-index="workIndex">
					<view class="uni-input">
					{{moneyText}}
					<image src="/static/img/buttom.png">
					</view>
				</picker>
			</view>
		</view>
	</view>
	
	 <view class="news">
	        <view class="newslist" v-for="(item,index) in list" :key="index" @click="jump(item.id,item.uid)">
	            <view  class="top">
	                <image v-if="item.imgs" :src="imgUrl+item.imgs[0]"></image>
	                <image v-else src="/static/img1/noup2.jpg"></image>
	                <view class="topright">
	                    <view class="jobname">{{item.job}}</view>
	                    <view class="jobnum">招聘人数:{{item.num}}</view>
	                    <view class="price">{{moneyArr[item.money]}}/月</view>
	                    <view class="jobcity">工作地点:{{item.city}}</view>
	                </view>
	            </view>
	            <view  class="nfooter">
	                <view class="jobname1">{{item.name}}</view>
	                <!--<view class="vprice">推荐人才</view>-->
	                <button @click="share" class="vprice">推荐人才</button>
	            </view>
	        </view>
	    </view>
</view>
</template>
<script>
import request from '@/util/request.js'	
export default {
	data() {
		return {
			imgUrl:this.url,
			city:'全部',
			jobText:'招聘岗位',
			jobIndex:0,
			job:[],
			pickJobArr:[
				{
					'id':0,
					'name':'招聘岗位',
					'addtime':'2020-10-20',
				}
			],
			moneyText:'薪资范围',
			moneyArr:['面议','5k以下','5k~8k','8k~10k','10k以上'],
			moneyIndex:0,
			page:1,
			pageShow:true,
			list:[],
			keyword:''
		}
	},
	onShow:function(){
		uni.showLoading({
		    title: '加载中'  
		});
		this.job = []
		this.page = 1;
		this.pageShow = true
		this.getJob();
		this.getCompany()
	},
	methods: {
		getJob:function(){
			var that = this;
			var pickJobArr = this.pickJobArr
			request({
				url: 'job/list',
				method: 'get',
				success: (res) => {
					that.job = pickJobArr.concat(res.data.data)
					that.jobText = that.job[that.jobIndex]['name']
				}
			})
		},
		getCompany:function(){
			if(this.city == '全部'){
				var city = '';
			}else{
				var city = this.city;
			}
			if(this.jobText == '招聘岗位'){
				var jobText = '';
			}else{
				var jobText = this.jobText;
			}
			var that = this
			var data = {
				city:city,
				page:this.page,
				keyword:this.keyword,
				money:this.moneyIndex,
				job:jobText
			}
			request({
				url: 'company/list',
				method: 'get',
				data:data,
				success: (res) => {
					uni.hideLoading();
					if(res.data.code == 1){
						if(res.data.data.last_page <= that.page){
							that.pageShow = false
						}
						if(that.page == 1){
							that.list = res.data.data.data
						}else{
							var list = that.list
							that.list = list.concat(res.data.data.data)
						}
					}
				}
			})
		},
		onReachBottom: function(){
			if(this.pageShow){
				 //当前不是最后一页可加载
				 this.page = this.page + 1
				 uni.showLoading()
				 this.getCompany();
			}
		},
		citySelect:function(){
			uni.navigateTo({
				url:'/pages/city/index'
			});
		},
		search:function(e){
			this.keyword = e.detail.value
			this.reset()
			uni.showLoading()
			this.getCompany();
		},
		bindMoneyChange:function(e){
			this.moneyIndex = e.detail.value
			this.moneyText = this.moneyArr[e.detail.value]
			this.reset()
			uni.showLoading()
			this.getCompany();
		},
		reset:function(){
			this.page = 1
			this.pageShow = true
		},
		bindJobChange:function(e){
			this.jobIndex = e.detail.value
			this.jobText = this.job[e.detail.value].name
			this.reset()
			uni.showLoading()
			this.getCompany();
		},
		jump:function(id,uid){
			uni.navigateTo({
				url:'/pages/company/info?id='+id+'&uid='+uid
			});
			return;
			if(uni.getStorageSync('role') == 99){
				uni.navigateTo({
					url:'/pages/company/info?id='+id+'&uid='+uid
				});
				return;
			}
			var role = wx.getStorageSync('role');
			if(role == 2){
				var data = {'uid':uni.getStorageSync('uid')}
				request({
					url: 'member/status',
					method: 'get',
					data:data,
					success: (res) => {
						if(res.data.data.status == 3){
							uni.navigateTo({
								url:'/pages/company/info?id='+id+'&uid='+uid
							});
						}else{
							uni.showToast({
								title: '审核未通过!!',
								icon: "none", 
								position:'bottom',
							});
							return;
						}
					}
				})
			}else{
				uni.showToast({
					title: '暂无权限!!',
					icon: "none", 
					position:'bottom',
				});
				return;
			}
		},
		share:function(){
			var img = '/static/img1/noup3.jpg'
			uni.share({
				provider: "weixin",
				scene: "WXSceneSession",
				type: 5,
				imageUrl:img,
				title:'人才招聘',
				miniProgram: {
					id: 'gh_42fb5eed1670',
					path: 'pages/index/index',
					type: 0,
					webUrl: 'https://www.tymyztc.com'
				},
				success: ret => {
					console.log(JSON.stringify(ret));
				}
			});
		}
	}
}
</script>
<style scoped>
	@import url("./css/index.css");
</style>